SQlite has no Column_Name problemi
SQLite ile oluşturduğum database'e insert işlemi yaparken has no column name problemi alıyorum kodlar ;
Veritabani.class:
package com.gokhangoy.diary; import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Veritabani extends SQLiteOpenHelper {
final public static String Database_Name = "GunlukUygulamasi";
final public static String Table_Name_Kullanicilar = "Kullanicilar";
final public static String Table_Name_Login = "Login"; f
inal public static String GunCol_0="ID";
final public static String GunCol_1="Adi";
final public static String GunCol_2="SoyAdi";
final public static String GunCol_3="Email";
final public static String GunCol_4="Password";
final public static String LogCol_1="KullaniciAdi";
final public static String LogCol_2="Password";
public Veritabani(Context context) { super(context, Database_Name, null,11); // SQLiteDatabase db =this.getWritableDatabase(); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE "+Table_Name_Kullanicilar+ "(ID INTEGER PRIMARY KEY AUTOINCREMENT,ADI TEXT,SOYADI TEXT,EMAIL TEXT,PASSWORD TEXT)");
db.execSQL("CREATE TABLE " + Table_Name_Login + "(KULLANICIADI TEXT,PASSWORD TEXT)"); // onUpgrade(db,1,4); }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + Table_Name_Kullanicilar); db.execSQL("DROP TABLE IF EXISTS "+Table_Name_Login); onCreate(db); ; }
public boolean KullaniciEkle(String Adi,String Soyadi,String Email,String Password) {
SQLiteDatabase db = this.getWritableDatabase(); //This line for checking ContentValues
con = new ContentValues();
con.put("GunCol_1",Adi);
con.put("GunCol_2",Soyadi);
con.put("GunCol_3",Email);
con.put("GunCol_4", Password);
long result = db.insert(Table_Name_Kullanicilar,null,con);
if(result == -1) return false;
else return true; } }
MainActivity.class:
package com.gokhangoy.diary;
import android.database.sqlite.SQLiteOpenHelper;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
Button btnLogIn;
EditText Adi,Soyadi,Email,Password ;
Veritabani mydb;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mydb = new Veritabani(this);
Adi = (EditText) findViewById(R.id.editText);
Soyadi = (EditText) findViewById(R.id.editText2);
Email = (EditText) findViewById(R.id.editText3);
Password = (EditText) findViewById(R.id.editText4);
btnLogIn = (Button) findViewById(R.id.button);
VeriEkle(); }
public void VeriEkle() {
btnLogIn.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
boolean kontrol = mydb.KullaniciEkle(Adi.getText().toString(),Soyadi.getText().toString(), Email.getText().toString(),Password.getText().toString());
if(kontrol == true)
Toast.makeText(getApplicationContext(), "Eklendi", Toast.LENGTH_LONG).show();
else Toast.makeText(getApplicationContext(),"Eklenemedi",Toast.LENGTH_LONG).show(); } }); } }
bu da log kaydı :
E/SQLiteLog﹕ (1) table Kullanicilar has no column named GunCol_4
03-18 12:01:08.873 1638-1638/? E/SQLiteDatabase﹕ Error inserting GunCol_4=q GunCol_3=q GunCol_2=qqq GunCol_1=q
android.database.sqlite.SQLiteException: table Kullanicilar has no column named GunCol_4 (code 1): , while compiling: INSERT INTO Kullanicilar(GunCol_4,GunCol_3,GunCol_2,GunCol_1) VALUES (?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
at com.gokhangoy.diary.Veritabani.KullaniciEkle(Veritabani.java:57)
at com.gokhangoy.diary.MainActivity$1.onClick(MainActivity.java:37)
at android.view.View.performClick(View.java:4438)
at android.view.View.onKeyUp(View.java:8241)
at android.widget.TextView.onKeyUp(TextView.java:5682)
at android.view.KeyEvent.dispatch(KeyEvent.java:2664)
at android.view.View.dispatchKeyEvent(View.java:7665)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2035)
at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1505)
at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
at android.support.v7.internal.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:49)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallback.dispatchKeyEvent(AppCompatDelegateImplBase.java:241)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3845)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3819)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3551)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3711)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2010)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1704)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1695)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1987)
at android.view.Inpu
Lütfen bu sorunu nasıl çözebilirim yardımcı olun :(